Namespacing everything to /UVa.
[andmenj-acm.git] / UVa / 11517 - Exact Change / c.cpp
blobe999a58485305876f3c7e3e1731b17de2d2c9c83
1 /*
2 Problem: 11517 - Exact Change
3 Author: Andrés Mejía-Posada
4 (http://blogaritmo.factorcomun.org)
6 Too much memory and too slow.
7 */
9 using namespace std;
10 #include <algorithm>
11 #include <iostream>
12 #include <iterator>
13 #include <sstream>
14 #include <fstream>
15 #include <cassert>
16 #include <climits>
17 #include <cstdlib>
18 #include <cstring>
19 #include <string>
20 #include <cstdio>
21 #include <vector>
22 #include <cmath>
23 #include <queue>
24 #include <deque>
25 #include <stack>
26 #include <map>
27 #include <set>
29 #define D(x) cout << #x " is " << x << endl
31 const int S = 10005, N = 105, oo = INT_MAX / 4;
33 int dp[N][S*N], c[N];
35 int main(){
37 int C;
38 cin >> C;
39 while (C--){
41 int price;
42 cin >> price;
44 int n;
45 cin >> n;
47 int sum = 0;
48 c[0] = oo; // Don't fuck
50 for (int i=1; i<=n; ++i){
51 cin >> c[i];
52 sum += c[i];
55 //sum = min(sum, price);
57 dp[0][0] = 0;
58 for (int j=1; j <= sum; ++j) dp[0][j] = oo;
60 for (int i=1; i<=n; ++i){
61 for (int j=0; j<=sum; ++j){
62 dp[i][j] = dp[i-1][j];
63 if (j - c[i] >= 0){
64 dp[i][j] = min(dp[i][j], dp[i-1][j-c[i]] + 1);
70 for (int i=0; i<=n; ++i){
71 for (int j=0; j<=sum; ++j){
72 printf("%10d ", dp[i][j]);
74 puts("");
78 for (int j=price; /*j <= sum*/; ++j){
79 if (dp[n][j] < oo){
80 cout << j << " " << dp[n][j] << endl;
81 break;
87 return 0;